package com.sunmouse.toolkit.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunmouse.toollib.adapter.BasicAdapter;
import com.sunmouse.toollib.utils.LogUtils;
import com.sunmouse.toolkit.R;

import java.util.List;

/**
 * Created by Administrator on 2017/7/27.
 */
public class TvListAdapter extends BasicAdapter<TvListAdapter.ViewHolder, String> {


    public TvListAdapter(List<String> list, Context context) {
        super(list, context);
    }

    @Override
    protected View bindView(LayoutInflater inflater, ViewGroup parent, Context context, List<String> list, int position) {
        View v = inflater.inflate(R.layout.adapter_list, parent, false);
        v.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                boolean focus = hasFocus;
            }

        });
        return v;
    }

    @Override
    protected ViewHolder bindViewHolder(View cv, ViewGroup parent, Context context) {
        return new ViewHolder(cv);
    }

    @Override
    protected void bindData(ViewHolder vh, final int position, List<String> list, Context context) {
        vh.nameTv.setText(list.get(position));
        vh.nameTv.setTag(position);
        vh.nameTv.requestFocusFromTouch();

        vh.nameTv.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                float textSize;
                if (hasFocus) {
                    textSize = 30.0f;
                } else {
                    textSize = 10.0f;
                }
                ((TextView) v).setTextSize(textSize);
//                v.postInvalidate();
                LogUtils.d("--------position="+v.getTag()+":"+textSize);
            }
        });
    }

    static class ViewHolder extends BasicAdapter.ViewHolder {
        TextView nameTv;

        public ViewHolder(View v) {
            super(v);
            this.nameTv = (TextView) v.findViewById(R.id.title_tv);
        }
    }
}
